package com.ruoyi.project.naming.namesentence.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.naming.namesentence.domain.NameSentence;
import com.ruoyi.project.naming.namesentence.service.INameSentenceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 起名名句Controller
 * 
 * @author shixiangwen
 * @date 2022-07-28
 */
@Controller
@RequestMapping("/naming/namesentence")
public class NameSentenceController extends BaseController
{
    private String prefix = "naming/namesentence";

    @Autowired
    private INameSentenceService nameSentenceService;

    @RequiresPermissions("naming:namesentence:view")
    @GetMapping()
    public String namesentence()
    {
        return prefix + "/namesentence";
    }

    /**
     * 查询起名名句列表
     */
    @RequiresPermissions("naming:namesentence:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NameSentence nameSentence)
    {
        startPage();
        List<NameSentence> list = nameSentenceService.selectNameSentenceList(nameSentence);
        return getDataTable(list);
    }

    /**
     * 导出起名名句列表
     */
    @RequiresPermissions("naming:namesentence:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NameSentence nameSentence)
    {
        List<NameSentence> list = nameSentenceService.selectNameSentenceList(nameSentence);
        ExcelUtil<NameSentence> util = new ExcelUtil<NameSentence>(NameSentence.class);
        return util.exportExcel(list, "namesentence");
    }

    /**
     * 新增起名名句
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存起名名句
     */
    @RequiresPermissions("naming:namesentence:add")
    @Log(title = "起名名句", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NameSentence nameSentence)
    {
        return toAjax(nameSentenceService.insertNameSentence(nameSentence));
    }

    /**
     * 修改起名名句
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        NameSentence nameSentence = nameSentenceService.selectNameSentenceById(id);
        mmap.put("nameSentence", nameSentence);
        return prefix + "/edit";
    }

    /**
     * 修改保存起名名句
     */
    @RequiresPermissions("naming:namesentence:edit")
    @Log(title = "起名名句", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NameSentence nameSentence)
    {
        return toAjax(nameSentenceService.updateNameSentence(nameSentence));
    }

    /**
     * 删除起名名句
     */
    @RequiresPermissions("naming:namesentence:remove")
    @Log(title = "起名名句", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(nameSentenceService.deleteNameSentenceByIds(ids));
    }
}
